package handler

import (
	"net/url"
	"sbd_zwjy/service"
	"sbd_zwjy/utils"
	"strconv"
)

type CompanyHandler struct {
	CompanySrv service.CompanyService
}

func (handler CompanyHandler) InsterCompanyHandler() {
	content := "biz_content=%7B%22param%22%3A%5B%7B%22name%22%3A%22%E5%8D%95%E4%BD%8D%E6%88%96%E4%B8%AA%E4%BA%BA%22%2C%22link%22%3A%22like%22%7D%5D%2C%22page%22%3A" +
		"1" +
		"%2C%22size%22%3A10%2C%22table%22%3A%22nyt_17%22%7D"
	sign := GetSignHandler(content)

	total, _ := ReListHandler(url.QueryEscape(sign), content)

	for i := 1; i <= total; i++ {
		contenta := "biz_content=%7B%22param%22%3A%5B%7B%22name%22%3A%22%E5%8D%95%E4%BD%8D%E6%88%96%E4%B8%AA%E4%BA%BA%22%2C%22link%22%3A%22like%22%7D%5D%2C%22page%22%3A" +
			strconv.Itoa(i) +
			"%2C%22size%22%3A10%2C%22table%22%3A%22nyt_17%22%7D"
		signa := GetSignHandler(contenta)
		_, results := ReListHandler(url.QueryEscape(signa), contenta)
		for _, v := range results {
			v.ID = utils.SnowId()
			handler.CompanySrv.InsterCompanySrv(v)
		}
	}
}
